
local AIMUM_MINLVL = 3

--################################################################################################################

minetest.register_node("lunomobs:chest_aimum", {
	description = "Bau do Farao Aimum (Lvl Min: "..AIMUM_MINLVL..")",
	tiles = {
		"text_chest_purple_top.png", --cima
		"text_chest_purple_bottom.png", --baixo
		"text_chest_purple_side.png", --direita
		"text_chest_purple_side.png", --esquerda
		"text_chest_purple_side.png", --traz
		"text_chest_purple_front.png", --frente
	},
	paramtype2 = "facedir",
	groups = {choppy=2,oddly_breakable_by_hand=2},
	legacy_facedir_simple = true,
	is_ground_content = false,
	sounds = default.node_sound_wood_defaults(),
	after_place_node = function(pos, placer, itemstack)
		local playername = placer:get_player_name()
		local ifPlace = minetest.check_player_privs(playername, {landrush=true})
		if not ifPlace then
			minetest.chat_send_player(playername,"Voce nao tem a permissão 'landrush' para instalar este bloco!")
		end
		return ifPlace
	end,
	on_construct = function(pos)
		local meta = minetest.get_meta(pos)
		--meta:set_string("formspec",default.chest_formspec)
		meta:set_string("infotext", "Bau do Farao Aimum")
		--local inv = meta:get_inventory()
		--inv:set_size("main", 8*4)
	end,
	on_rightclick = function(pos, node, clicker, itemstack)
		local playername = clicker:get_player_name()
		local level = lunomods.getLevel(playername)
		if level >= AIMUM_MINLVL then
			local questvalue = lunomods.getCharValue(playername, "quest_aimum")
			--print("questvalue='"..dump(questvalue).."' tipe="..type(questvalue))
			if questvalue~=true then
				print(playername.." abriu o Bau de Farao Aimum...")
				local bossAimum = minetest.env:add_entity({x=pos.x, y=pos.y+2, z=pos.z}, "lunomobs:pharaoh")
				--lunomobs.doMobSFX(clicker, bossAimum, "bmg_ButterflyTea_RiseOfLegend", false)
				--bossAimum:get_luaentity().bmg_buffer = 
				minetest.sound_play("bmg_ButterflyTea_RiseOfLegend", {pos=pos, max_hear_distance = 10})
			else
				minetest.chat_send_player(playername,"Nao tem nada no bau para voce pois ja completou a missao 'FARAO AIMUM'!")
			end
		else
			minetest.chat_send_player(playername,"Nao tem forca suficiente para abrir o 'BAU DO FARAO AIMUM'!")
		end
	end,
})

minetest.register_alias("chestaimum"		, "lunomobs:chest_aimum")
minetest.register_alias("chestpharaoh"		, "lunomobs:chest_aimum")
minetest.register_alias("baudofarao"		, "lunomobs:chest_aimum")
minetest.register_alias("baudoaimum"		, "lunomobs:chest_aimum")

--################################################################################################################


minetest.register_tool("lunomobs:sword_pharaoh", {
	description = "Espada do REI AIMUM",
	inventory_image = "obj_sword_epic01.png",
	tool_capabilities = {
		full_punch_interval = 0.5,
		max_drop_level=1,
		groupcaps={
			snappy={times={[1]=1.90, [2]=0.90, [3]=0.30}, uses=40, maxlevel=3},
		},
		damage_groups = {fleshy=9},
	}
})

minetest.register_alias("espadareiescaravelho"		, "lunomobs:sword_pharaoh")
minetest.register_alias("espadadoreiescaravelho"	, "lunomobs:sword_pharaoh")
minetest.register_alias("espadafarao"					, "lunomobs:sword_pharaoh")
minetest.register_alias("espadadofarao"				, "lunomobs:sword_pharaoh")

--################################################################################################################

lunomobs:register_mob("lunomobs:mummy", {
	type = "monster",
	mob_name="ESCRAVO MUMIA",
	hp_max = 4, --Padrão = 4
	xp_give = 0,
	--pos ={0.0,0.0,0.0},
	jump = true, 
	visual = "mesh",
	--mesh="mobs_sand_monster.x",
	mesh="mobs_humanoid.b3d",
	--mesh="teste01.x3d", --do blender(Exportado nao sei se fiz correto)
	--mesh="women.x", --(Conseguido de local externo. sem textura)
	textures = {"mobs_humanoid_mummy.png"},
	collisionbox = {-0.3,-1.0,-0.3, 0.3,0.8,0.3},
	--visual_size = {x=8,z=10},
	visual_size= {x=1, y=1},
	drawtype = "front",
	makes_footstep_sound = true,
	view_range = 7,
	walk_velocity = 1,
	run_velocity = 1.5,
	damage = 3, --Se for 1 pode ser q o player nem sinta o dano!
	--drops = {},
	drops = { 
		--{name="default:gold_lump", chance = 20, min=1, max=3 ,},	--Probabilidade é de 1:20 (=5%) de cair entre 1 a 3 "punhados de ouro"
	},
	light_resistant = true,
	armor = 100,
	water_damage = 1, --1=Morte lenta
	lava_damage = 10,
	light_damage = 0,
	shadow_damage = 0,
	attack_type = "dogfight",
	hyper_aggressive = true,
	animation = {
		speed_normal=15, speed_run=15, --speed_run=30 (Padrao)
		stand_start=0, stand_end=79,
		walk_start=168, walk_end=187,
		run_start=168, run_end=187,
		punch_start=189, punch_end=199, --Ataca Parado.
		--punch_start=200, punch_end=219, --Ataca correndo. (incorreto! Pois o npc so ataca paradop quando chega perto.)
		--punch_start=81, punch_end=161, --sentado
	},
	sounds = {
		--random = "sword_1",
		--random = "mobs_thief",
		random = "mobs_human_zombie_die",
		attack = "sword_2",
		hit = "sword_2",
		die = "sword_3", --Não existe som de morte! (mas eu fiz acontecer ^.^)
	},
	--follow = "lunotrades:minecoin",
	--FONTE: https://github.com/PilzAdam/mobs/wiki/API
})

--################################################################################################################

lunomobs:register_mob("lunomobs:pharaoh", {
	type = "boss",
	mob_name="REI AIMUM",
	hp_max = 120, --Padrão = 4
	xp_give = 100,
	armor = 70, --(PADRAO: 200)
	--pos ={0.0,0.0,0.0},
	jump = true, 
	visual = "mesh",
	--mesh="mobs_sand_monster.x",
	mesh="mobs_humanoid.b3d",
	--mesh="teste01.x3d", --do blender(Exportado nao sei se fiz correto)
	--mesh="women.x", --(Conseguido de local externo. sem textura)
	textures = {"mobs_humanoid_pharaoh3.png"},
	--collisionbox = {-0.3,-1.0,-0.3, 0.3,0.8,0.3},
	--visual_size= {x=1, y=1},
	collisionbox = {-0.4,-1.3,-0.4, 0.7,1.0,0.4},
	visual_size= {x=1.3, y=1.3},
	drawtype = "front",
	makes_footstep_sound = true,
	view_range = 7,
	walk_velocity = 1,
	run_velocity = 3,
	damage = 5,
	--drops = {},
	drops = { 
		{name="lunotrades:minecoin", chance = 1, min=1, max=7 ,},	--Probabilidade é de 1:1 (=100%) de cair entre 1 a 5 "lunotrades:minecoin".
		{name="lunomobs:sword_pharaoh", give=1, quest="quest_aimum"}, --Entrega uma "lunomobs:sword_pharaoh" se não estiver feito a quest "quest_pharaoh" antes.
	},
	light_resistant = true,
	water_damage = 1, --1=Morte lenta
	lava_damage = 10,
	light_damage = 0,
	shadow_damage = 0,
	attack_type = "spawner",
	hyper_aggressive = true,
	spawner = {
		mob = "lunomobs:mummy",
		amount = 4,
		dist = 2, 
		sound = "mobs_born",
		kills_children_on_die = true,
	},
	animation = {
		speed_normal=15, speed_run=30,
		stand_start=0, stand_end=79,
		walk_start=168, walk_end=187,
		run_start=168, run_end=187,
		punch_start=189, punch_end=199, --Ataca Parado.
		--punch_start=200, punch_end=219, --Ataca correndo. (incorreto! Pois o npc so ataca paradop quando chega perto.)
		--punch_start=81, punch_end=161, --sentado
	},
	sounds = {
		--random = "sword_1",
		--random = "mobs_thief",
		--random = "mobs_born", --Ele spawn mobs por isso tem q ser som de pondo ovo!
		attack = "mobs_born", --Ele spawn mobs por isso tem q ser som de pondo ovo!
		hit = "sword_2",
		die = "mobs_human_male_die", --Não existe som de morte! (mas eu fiz acontecer ^.^)
	},
	follow = "lunotrades:minecoin",
	--FONTE: https://github.com/PilzAdam/mobs/wiki/API
})


--[[
lunomobs:register_spawn("lunomobs:pharaoh", {
	"default:dirt", "default:dirt_with_grass", "watershed:grass", 
	"default:grass_1", "default:grass_2", "default:grass_3", "default:grass_4", "default:grass_5", 
	"default:dirt_with_snow", "default:snowblock", "default:ice", 
	"default:sand", "default:desert_sand", "default:mossycobble"
	}, 20, 11, 7000, 4, 31000
)

]]--

minetest.register_craftitem("lunomobs:pharaoh", {
	description = "Farao",
	groups = { mobs=1 },
	inventory_image = "mob_humanoid_pharaoh.png",
	on_place = function(itemstack, placer, pointed_thing)
		if pointed_thing.above then
			local spawnpos = pointed_thing.above
			spawnpos = {x=spawnpos.x, y=spawnpos.y+1, z=spawnpos.z}
			minetest.env:add_entity(spawnpos, "lunomobs:pharaoh")
			if not minetest.setting_getbool("creative_mode") then itemstack:take_item() end
		end
		return itemstack
	end,
})

minetest.register_alias("pharaoh"	, "lunomobs:pharaoh")
minetest.register_alias("farao"		, "lunomobs:pharaoh")

